package ferp.android.widgets.callouts;

import android.content.Context;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import ferp.android.R;
import ferp.android.widgets.BidView;
import ferp.core.game.Bid;

/**
 * User: igorgok
 * Date: 12/30/13 12:25 PM
 */
public abstract class Callout extends LinearLayout
{
  // instances are created only in the code
  public Callout(Context context)
  {
    super(context);

    // adjust own parameters
    setOrientation(HORIZONTAL);
    setGravity(Gravity.CENTER);
    setBackgroundResource(getBackgroundResource());

    // create embedded bid view
    bv = new BidView(context, SCALE_FACTOR_X, SCALE_FACTOR_Y);

    addView(bv, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
  }

  public void show(Bid bid, boolean animate)
  {
    bv.show(bid);

    setVisibility(VISIBLE);

    // animate only for androids and not resumed game
    if (animate)
      startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.callout_show));
  }

  public void hide()
  {
    setVisibility(INVISIBLE);
    clearAnimation();
  }

/*
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
  {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    //if (getVisibility() != GONE)
    //  Log.debug(Log.TAG, "CO2 onMeasure " + GUI.m2s(widthMeasureSpec, heightMeasureSpec) + " -> " + getMeasuredWidth() + "x" + getMeasuredHeight());
  }

  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b)
  {
    super.onLayout(changed, l, t, r, b);

    //if (getVisibility() != GONE)
    //  Log.debug(Log.TAG, "CO2 onLayout " + l + "x" + t + " - " + r + "x" + b);
  }
*/

  protected abstract int getBackgroundResource();

  private static final float SCALE_FACTOR_X = 0.83f;
  private static final float SCALE_FACTOR_Y = 0.4f;

  // embedded bid view
  private final BidView bv;
}
